package com.toolbox.controller.infra;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.toolbox.annotation.OperateLog;
import com.toolbox.base.BaseController;
import com.toolbox.req.InfraRoleMenuReq;
import com.toolbox.result.ResponseResultDTO;
import com.toolbox.service.InfraRoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色菜单表 前端控制器
 * </p>
 *
 * @author Mango
 * @since 2023-12-01
 */
@SuppressWarnings("ALL")
@ApiSort(100)
@Api(tags = "角色菜单表 前端控制器")
@RestController
@RequestMapping("/role-menu-do")
public class InfraRoleMenuController extends BaseController {

    @Autowired
    private InfraRoleMenuService service;

    /**
     * 创建——角色与菜单关系
     *
     * @param roleId  角色ID
     * @param menuIds 菜单ID
     */
    @OperateLog(operateName = "创建——角色与菜单关系", operateItem = "infra_role_menu")
    @ApiOperationSupport(order = 100)
    @ApiOperation(value = "创建——角色与菜单关系")
    @PostMapping(value = "/create-role-menu")
    public ResponseResultDTO<Void> createRoleMenu(@RequestBody @Validated InfraRoleMenuReq req) {
        service.save(req.getRoleId(), req.getMenuIds(), init());
        return ResponseResultDTO.success();
    }

    /**
     * 删除——角色与菜单关系
     *
     * @param id 主键ID
     */
    @OperateLog(operateName = "删除——角色与菜单关系", operateItem = "infra_role_menu")
    @ApiOperationSupport(order = 100)
    @ApiOperation(value = "删除——角色与菜单关系")
    @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", dataTypeClass = Long.class, paramType = "query", example = "1", required = true)
    @DeleteMapping(value = "/remove-by-id")
    public ResponseResultDTO<Void> removeById(@RequestParam(name = "id") Long id) {
        service.removeById(id);
        return ResponseResultDTO.success();
    }

}
